package com.naiterui.ehp.bs.recommend.controller.inner;

import com.naiterui.ehp.bp.bo.recommend.MedicationRecomBO;
import com.naiterui.ehp.bp.bo.recommend.MedicationRecomDetailBO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.PublicService;
import com.naiterui.ehp.bp.support.exception.ResponseVO;
import com.naiterui.ehp.bp.utils.date.DateUtil;
import com.naiterui.ehp.bp.utils.lang.StringUtil;
import com.naiterui.ehp.bs.recommend.exception.ExceptionCodes;
import com.naiterui.ehp.bs.recommend.service.IDrPtRecomService;
import io.swagger.annotations.Api;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 医生端调用推荐服务接口(hessian迁移)
 *
 * @author guoyongxiang
 * @date 2019-06-28 14:54
 * @since 1.0.0
 */
@Api(tags = {SwaggerTag.INNER_API + SwaggerTag.RECOM, SwaggerTag.DOCTOR + SwaggerTag.RECOM})
@RequestMapping("recommend/inner/dr/recom")
@RestController
public class InnerRecomDrController {

    private static final Logger LOGGER = LoggerFactory.getLogger(InnerRecomDrController.class);

    @Autowired
    private IDrPtRecomService drPtRecomService;

    @RequestMapping("details")
    public ResponseVO<List<MedicationRecomDetailBO>> details(String recommendIds) {
        Set<Long> recomIdSet = StringUtil.convertLongStr2Set(recommendIds, ",");
        List<MedicationRecomDetailBO> detailBOList = drPtRecomService.getRecomDetails(recomIdSet);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS, detailBOList);
    }


    @PostMapping("specifyday")
    public ResponseVO<List<MedicationRecomBO>> specifyday(String recommendIds, String start, String end) {
        Date startDate = DateUtil.parseStrToDateTime(start);
        Date endDate = DateUtil.parseStrToDateTime(end);
        List<Integer> recomStatus = StringUtil.convertIntegerStr2List(recommendIds, ",");
        List<MedicationRecomBO> list = drPtRecomService.getSpecifydayRecom(recomStatus, startDate, endDate);
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS, list);
    }

    @PostMapping("getRecomStatusMap")
    public ResponseVO<Map<Long, Integer>> getRecomStatusMap(@RequestBody Set<Long> recomIds) {
        return PublicService.returnResponseVO(ExceptionCodes.SUCCESS, drPtRecomService.getRecomStatusMap(recomIds));
    }
}
